import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
    const env = loadEnv(mode, process.cwd());
    console.log(env.VITE_API_HOST);
    
    return {
        plugins: [vue()],
        resolve: {
            // 別名
            alias: {
                '@': resolve(__dirname, 'src')
            }
        },
        server: {
            host: "0.0.0.0",
            proxy: {
                // 反向代理
                '/api': {
                    target: env.VITE_API_HOST,
                    changeOrigin: true,
                    secure: false,
                    rewrite: (path) => path.replace(/^\/api/, env.VITE_MODE == 'dev' ? '' : ''),
                },
                '/res': {
                    target: env.VITE_APP_HOST,
                    changeOrigin: true,
                    secure: false,
                    rewrite: (path) => path.replace(/^\/res/,  'res'),
                },
            }
        }
    }
})
